package com.dsh.authorityManagement.controller;

import com.dsh.authorityManagement.entity.dto.IdsDto;
import com.dsh.authorityManagement.entity.dto.UserDto;
import com.dsh.authorityManagement.entity.vo.ImportUserVo;
import com.dsh.authorityManagement.entity.vo.UserVo;
import com.dsh.authorityManagement.service.UserService;
import com.dsh.model.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "用户管理")
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    UserService userService;
    @PostMapping("insertUser")
    @ApiOperation("添加用户")
    public Result insertUser(UserDto userDto){
        int i = userService.insertUser(userDto);
        return Result.success(i,"");
    }
    @PostMapping("insertUserForVx")
    @ApiOperation("通过微信添加用户")
    public Result insertUserForVx(UserDto userDto){
        int i = userService.insertUserForVx(userDto);
        return Result.success(i,"");
    }
    @ApiImplicitParam(paramType="query", name = "id", value = "被审核人员id", required = true, dataType = "int")
    @ApiOperation("用户审核通过")
    @PostMapping("passed")
    public Result passed(int id){
        int passed = userService.passed(id);
        return  Result.success(passed,"");

    }
    @ApiImplicitParam(paramType="query", name = "id", value = "被审核人员id", required = true, dataType = "int")
    @ApiOperation("用户审核不通过")
    @PostMapping("noPassed")
    public Result noPassed(int id){
        int noPassed = userService.noPassed(id);
        return  Result.success(noPassed,"");

    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "limit", value = "分页大小", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "page", value = "分页数", required = true, dataType = "int"),
//            @ApiImplicitParam(paramType="query", name = "username", value = "用户名", required = true, dataType = "int"),
//            @ApiImplicitParam(paramType="query", name = "phone", value = "电话", required = true, dataType = "int")
    })
    @ApiOperation(("用户名，所在机构名，角色名以及用户id，用户电话"))
    @GetMapping("selectUsernameAndRoleNameAndStoreName")
    public  Result selectUsernameAndRoleNameAndStoreName(String username,String phone,int limit, int page){
        PageInfo<UserDto> userDtoPageInfo = userService.selectUsernameAndRoleNameAndStoreName(username,phone,limit, page);
        return Result.success(userDtoPageInfo,"");
    }
    @ApiOperation("导入的用户以及所在机构id")
    @GetMapping("importUserVos")
    public  Result importUserVos(){
        List<ImportUserVo> importUserVos = userService.selectImportUser();
        return  Result.success(importUserVos,"");
    }
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "人员ID数组", dataType = "int", paramType = "body", allowMultiple = true, required = true ),
            @ApiImplicitParam(paramType="query", name = "sId", value = "机构id", required = true, dataType = "int")})
    @ApiOperation("确认导入人员")
    @PostMapping("ImportUser")
    public  Result ImportUser(@RequestBody Integer[] ids, int sId){
        this.userService.ImportUser(ids, sId);
        return Result.success("");
    }
    @GetMapping("selectAdminByAdminId")
    @ApiImplicitParam(paramType="query", name = "id", value = "人员的id", required = true, dataType = "int")
    @ApiOperation("根据id用户名，所在机构名，角色名以及用户id，用户电话")
    public Result selectAdminByAdminId(int id){
        List<UserVo> userVos = userService.selectAdminByAdminId(id);
        return Result.success(userVos,"");
    }
}
